package com.ww.basic.implicits

import java.time.LocalDate

/**
 * 增强第三方类（无侵入扩展）
 */
object Test4 {
  implicit class RichTradingDate(date: LocalDate) {
    // 假设非周末即为交易日
    def minusTradingDays(n: Int): LocalDate = {
      var result = date
      var count = 0
      while (count < n) {
        result = result.minusDays(1)
        if (result.getDayOfWeek.getValue < 6) count += 1 // 排除周六（6）、周日（7）
      }
      result
    }
  }

  def main(args: Array[String]): Unit = {
    val today = LocalDate.of(2025, 11, 25)
    val last5TradingDays = today.minusTradingDays(5)
    println(last5TradingDays)
  }
}
